package com.abacus.lcy.m;

import java.lang.reflect.Field;

public class ValueParserHelper {
	private static final Field[] fields = ValueParser.class.getDeclaredFields();

	public static final String getValueParser(String valueParser) {
		if (null != valueParser) {
			for (int i = 0; i < fields.length; i++) {
				if (fields[i].getType() == String.class) {
					Object value;
					try {
						value = fields[i].get(null);
						if (valueParser.equals(value)) {
							return (String) value;
						}
					} catch (IllegalArgumentException e) {
						e.printStackTrace();
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					}
				}
			}
		}
		return null;
	}

	public static final String getValueParser(Integer valueParserCode) {
		if (null != valueParserCode) {
			for (int i = 0; i < fields.length; i++) {
				if (fields[i].getType() == Integer.class) {
					Object value;
					try {
						value = fields[i].get(null);
						if (valueParserCode.equals(value)) {
							return (String) ValueParser.class.getField(
									fields[i].getName().substring(0, fields[i].getName().length() - 5)).get(null);
						}
					} catch (IllegalArgumentException e) {
						e.printStackTrace();
					} catch (IllegalAccessException e) {
						e.printStackTrace();
					} catch (SecurityException e) {
						e.printStackTrace();
					} catch (NoSuchFieldException e) {
						e.printStackTrace();
					}
				}
			}
		}
		return null;
	}
}
